// 获取用户列表 byTimeTag 0-默认顺序,1-时间从大到小,2-时间从小到大
function getUserList(byTimeTag) {
    $.ajax({
        url : "/SofaGuest/login/qryUser.do",
        type : "post",
        data : {
            "byTimeTag" : byTimeTag
        },
        dataType : "json",
        success : function(result) {
            // alert(result.detial);
            if ("0000" == result.status) {
                $("#userList").html("");
                var users = result.data;
                for ( var i = 0; i < users.length; i++) {
                    var user = users[i];
                    var joinTime = user.join_time.substring(0, 10);
                    var tr = '<tr><td>' + user.user_id + '</td><td>' + user.real_name + '</td><td>' + user.tel_phone
                            + '</td>' + '<td>' + transUserType(user.user_type) + '</td><td>' + joinTime
                            + '</td><td><a href="Javascript:void(0)" onclick="deleteThis(this)">删除</a></td></tr>';
                    var $tr = $(tr);
                    $tr.data("id", user.user_id);
                    $tr.data("type", "user");
                    $("#userList").append($tr);
                }
                $(".sortList").data("type", "user");
            }
        },
        error : function() {
            alert("获取用户列表异常,请稍后重试");
        }
    });
}

// 2.给三个按钮设置默认的值
function setDefault() {
    $("#default").data("value", "0");
    $("#byTimeBig").data("value", "1");
    $("#byTimeSmall").data("value", "2");
}

// 查看沙发的信息
function getSofaList(byTimeTag) {
    $.ajax({
        url : "/SofaGuest/sofa/getSofaList.do",
        type : "post",
        data : {
            "byTimeTag" : byTimeTag
        },
        dataType : "json",
        success : function(result) {
            // alert(result.detial);
            $("#sofaList").html("");
            if ("0000" == result.status) {
                var sofas = result.data;
                for ( var i = 0; i < sofas.length; i++) {
                    var sofa = sofas[i];
                    var tr = '<tr><td>' + sofa.real_name + '</td><td>' + sofa.sofa_address + '</td><td>'
                            + sofa.sofa_type + '</td>' + '<td>' + sofa.tel_phone + '</td><td>' + sofa.join_date
                            + '</td><td><a href="Javascript:void(0)" onclick="deleteThis(this)">删除</a></td></tr>';
                    var $tr = $(tr);
                    $tr.data("id", sofa.sofa_id);
                    $tr.data("type", "sofa");
                    $("#sofaList").append($tr);
                }
                $(".sortList").data("type", "sofa");
            }
        },
        error : function() {
            alert("获取沙发信息异常,请稍后重试");
        }
    });
}

// 查看订单信息
function getOrderList(byTimeTag) {
    $.ajax({
        url : "/SofaGuest/order/getOrderList.do",
        type : "post",
        data : {
            "byTimeTag" : byTimeTag
        },
        dataType : "json",
        success : function(result) {
            // alert(result.detial);
            $("#orderList").html("");
            if ("0000" == result.status) {
                var orders = result.data;
                for ( var i = 0; i < orders.length; i++) {
                    var order = orders[i];
                    var tr = '<tr><td>' + order.order_id + '</td><td>' + order.user_name + '</td><td>' + order.user_tel
                            + '</td><td>' + order.order_start_date + '</td><td>' + transOrderStatus(order.order_status)
                            + '</td><td><a href="Javascript:void(0)" onclick="deleteThis(this)">删除</a></td></tr>';
                    var $tr = $(tr);
                    $tr.data("id", order.order_id);
                    $tr.data("type", "order");
                    $("#orderList").append($tr);
                }
                $(".sortList").data("type", "order");
            }
        },
        error : function() {
            alert("获取沙发信息异常,请稍后重试");
        }
    });
}

// 查看留言信息
function getMassageList(byTimeTag) {
    $.ajax({
        url : "/SofaGuest/travel/getMassageList.do",
        type : "post",
        data : {
            "byTimeTag" : byTimeTag
        },
        dataType : "json",
        success : function(result) {
            // alert(result.detial);
            $("#msgList").html("");
            if ("0000" == result.status) {
                var msgs = result.data;
                for ( var i = 0; i < msgs.length; i++) {
                    var msg = msgs[i];
                    var tr = '<tr><td>' + msg.real_name + '</td><td>' + msg.massage + '</td><td>' + msg.massage_date
                            + '</td><td><a href="Javascript:void(0)" onclick="deleteThis(this)">删除</a></td></tr>';
                    var $tr = $(tr);
                    $tr.data("id", msg.massage_id);
                    $tr.data("type", "msg");
                    $("#msgList").append($tr);
                }
                $(".sortList").data("type", "msg");
            }
        },
        error : function() {
            alert("获取沙发信息异常,请稍后重试");
        }
    });
}

// 查看游记信息
function getTravelList(byTimeTag) {
    $.ajax({
        url : "/SofaGuest/travel/getTravelList.do",
        type : "post",
        data : {
            "byTimeTag" : byTimeTag
        },
        dataType : "json",
        success : function(result) {
            // alert(result.detial);
            $("#travelList").html("");
            if ("0000" == result.status) {
                var travels = result.data;
                for ( var i = 0; i < travels.length; i++) {
                    var travel = travels[i];
                    var tr = '<tr><td>' + travel.note_tatile + '</td><td>' + travel.real_name + '</td><td>'
                            + transUserType(travel.user_type) + '</td><td>' + travel.send_date
                            + '</td><td><a href="Javascript:void(0)" onclick="deleteThis(this)">删除</a></td></tr>';
                    var $tr = $(tr);
                    $tr.data("id", travel.note_id);
                    $tr.data("type", "travel");
                    $("#travelList").append($tr);
                }
                $(".sortList").data("type", "travel");
            }
        },
        error : function() {
            alert("获取沙发信息异常,请稍后重试");
        }
    });
}

// 删除信息
function deleteThis(tr) {
    var id = $(tr).parent().parent().data("id");
    var type = $(tr).parent().parent().data("type");
    $.ajax({
        url : "/SofaGuest/login/managerInfo.do",
        type : "post",
        data : {
            "acctId" : acctId,
            "id" : id,
            "type" : type
        },
        dataType : "json",
        success : function(result) {
            alert(result.detial);
            transSort(type, 0);
        },
        error : function() {
            alert("删除信息异常,请稍后重试");
        }
    });

}
